﻿#region
using System;
using System.Windows.Forms;

#endregion

namespace ComicsDownloader
{
    public static class WinformUtility
    {
        #region InvokeIfNeeded
        public static void InvokeIfNeeded(this Control control, Action action)
        {
            if (control.InvokeRequired)
                control.Invoke(action);
            else
                action();
        }

        public static void InvokeIfNeeded<T>(this Control control, Action<T> action, T arg)
        {
            if (control.InvokeRequired)
                control.Invoke(action, arg);
            else
                action(arg);
        }

        public static void InvokeIfNeeded<T1, T2>(this Control control, Action<T1, T2> action, T1 arg1, T2 arg2)
        {
            if (control.InvokeRequired)
                control.Invoke(action, arg1, arg2);
            else
                action(arg1, arg2);
        }

        public static void InvokeIfNeeded<T1, T2, T3>(this Control control, Action<T1, T2, T3> action, T1 arg1, T2 arg2,
            T3 arg3)
        {
            if (control.InvokeRequired)
                control.Invoke(action, arg1, arg2, arg3);
            else
                action(arg1, arg2, arg3);
        }

        public static void InvokeIfNeeded<T1, T2, T3, T4>(this Control control, Action<T1, T2, T3, T4> action, T1 arg1,
            T2 arg2, T3 arg3, T4 arg4)
        {
            if (control.InvokeRequired)
                control.Invoke(action, arg1, arg2, arg3, arg4);
            else
                action(arg1, arg2, arg3, arg4);
        }
        #endregion
    }
}